#include <gtest/gtest.h>
#include <iostream>
#include <string>
#include "Vector.hpp"
using namespace cr;

// TestCase 事件(即: 全局事件+TestSuite 事件)

class VectorTest : public testing::Test
{
public:
    static void SetUpTestCase() // 全局单元测试
    {
        // 处理全局的测试数据对象
        std::cout << "全局单元测试初始化" << std::endl;
    }

    virtual void SetUp() override // 独立单元测试
    {
        // 处理每个单元测试所需的独立数据对象（成员对象）
        std::cout << "当前单元测试初始化" << std::endl;
    }

    virtual void TearDown() override
    {
        std::cout << "当前单元测试环境释放" << std::endl;
    }

    static void TearDownTestCase()
    {
        std::cout << "全局单元测试释放" << std::endl;
    }

public:
    Vector<int> v;
};

TEST_F(VectorTest, construct)
{
    Vector<int> v1;
    Vector<int> v2(10, 5);
    std::cout << v2 << std::endl;

    int arr[] = {1, 2, 3, 4, 5};
    Vector<int> v3(arr, arr + sizeof(arr) / sizeof(int));
    std::cout << v3 << std::endl;

    Vector<int> v4(3);
    std::cout << v4 << std::endl;
}

TEST_F(VectorTest, access)
{
    Vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    v1.push_back(5);
    ASSERT_EQ(v1.size(), 5);
    ASSERT_EQ(v1.capacity(), 8);
    ASSERT_EQ(v1.front(), 1);
    ASSERT_EQ(v1.back(), 5);
    std::cout << v1 << std::endl;

    v1.pop_back();
    v1.pop_back();
    ASSERT_EQ(v1.back(), 3);
    std::cout << v1 << std::endl;

    v1.insert(v1.begin() + 1, 20);
    std::cout << v1 << std::endl;
    v1.erase(v1.begin() + 2);
    std::cout << v1 << std::endl;
    ASSERT_EQ(v1.size(), 3);
    ASSERT_EQ(v1[1], 20);
}

TEST_F(VectorTest, string)
{
    Vector<std::string> vs;
    vs.push_back("a");
    vs.push_back("ab");
    vs.push_back("abc");
    vs.push_back("abcd");
    vs.push_back("abcde");
    vs.push_back("abcdef");
    vs.push_back("abcdefg");
    vs.push_back("abcdefgh");
    vs.push_back("abcdefghi");
    std::cout << vs << std::endl;
    Vector<std::string> copy(move(vs));
    std::cout << copy << std::endl;
}

TEST_F(VectorTest, reverse_iterator)
{
    Vector<int> rv(3, 7);
    rv.push_back(1);
    rv.push_back(2);
    rv.push_back(3);
    rv.push_back(4);
    rv.push_back(5);
    rv.push_back(6);
    Vector<int>::reverse_iterator rit = rv.rbegin();
    while (rit != rv.rend())
    {
        std::cout << *rit << ' ';
        rit++;
    }
    std::cout << std::endl;
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);

    return RUN_ALL_TESTS();
}